package com.atguigu.spzx.model.vo.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "返回结果")
public class Result<T> {
    @Schema(description = "状态码")
    private Integer code;
    @Schema(description = "信息")
    private String message;
    private T data;

    public static <T> Result<T> build(T body, Integer code, String message){
        Result<T> result = new Result<>();
        result.setData(body);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> OK(T data){
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(200);
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> FAIL(){
        Result<T> result = new Result<>();
        result.setData(null);
        result.setCode(500);
        result.setMessage("失败");
        return result;
    }

    public static <T> Result<T> FAIL(String message){
        Result<T> result = new Result<>();
        result.setData(null);
        result.setCode(500);
        result.setMessage(message);
        return result;
    }

    public static Result OK() {
        Result result = new Result<>();
        result.setMessage("成功");
        return result;
    }
}
